## Various linear transforms
im = imread('sample.jpg');
figure (); 
ima = imshow (im);
xlabel ('Original')
%input space corners
incp = [1 1; 1767 1; 1767 2172; 1 2172];
udata = [min(incp(:,1)) max(incp(:,1))];
vdata = [min(incp(:,2)) max(incp(:,2))];
%subplot (2,3,1); 
%imshow (im)
%hold on
%plot (incp(:,1), incp(:,2), 'ob')
%axis on
%xlabel ('Original')


% Projection - expand the top edge of the image
%outcp = [-62 1; 1830 1; 1767 2172; 1 2172];
outcp = [-96 1; 1863 1; 1767 2172; 1 2172];
T = maketform ('projective', incp, outcp)
%subplot (2,3,6); 
[im2 xdata ydata] = imtransform (im, T, 'udata', udata, 'vdata', vdata, 'fillvalues', 1 );
figure();
imh = imshow (im2); set (imh, 'xdata', xdata, 'ydata', ydata) 
set (gca, 'xlim', xdata, 'ylim', ydata)
axis on, hold on, xlabel ('Projection');
plot (outcp(:,1), outcp(:,2), 'or')
xlabel('expanded');
imwrite(im2, 'sample.transform.expand.png', 'png');


% Projection - shrink the bottom edge of the image
%outcp = [1 1; 1767 1; 1705 2172; 62 2172];
outcp = [1 1; 1767 1; 1671 2172; 96 2172];
T = maketform ('projective', incp, outcp)
%subplot (2,3,6); 
[im3 xdata ydata] = imtransform (im, T, 'udata', udata, 'vdata', vdata, 'fillvalues', 1 );
figure();
img = imshow (im3); set (img, 'xdata', xdata, 'ydata', ydata) 
set (gca, 'xlim', xdata, 'ylim', ydata)
axis on, hold on, xlabel ('Projection');
plot (outcp(:,1), outcp(:,2), 'or')
xlabel('shrinked');
imwrite(im3, 'sample.transform.shrink.png', 'png');
